package cn.pku.edu.cs.ldn.view;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Path;
import android.graphics.PorterDuff;
import android.graphics.Region;
import android.util.AttributeSet;
import android.util.Log;
import android.widget.ImageView;

/**
 * Deprecated
 * 
 * @author ldn
 * 
 */
public class RoundedImageView extends ImageView {
	private static final String TAG = "RoundedImageView";
	private static final boolean DEBUG = true;

	public RoundedImageView(Context context) {
		super(context);
		init();
	}

	public RoundedImageView(Context context, AttributeSet attrs) {
		super(context, attrs);
		init();
	}

	public RoundedImageView(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		init();
	}

	private void init() {
		p = new Path();
	}

	Path p;

	@Override
	protected void onDraw(Canvas canvas) {
		int width = getWidth();
		int height = getHeight();
		if (DEBUG)
			Log.v(TAG, "onDraw: " + width + " " + height);
		if (p.isEmpty()) {
			p.addCircle(width / 2F, height / 2F, width / 2F, Path.Direction.CW);
		}

		canvas.clipPath(p, Region.Op.REPLACE);
		canvas.drawColor(0x00000000, PorterDuff.Mode.CLEAR);
		super.onDraw(canvas);
	}

}
